package ds.factcom.model;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import ds.factcom.domain.item.Item;

@SuppressWarnings("serial")
public class ItemTableModel extends AbstractTableModel {

	private String[] columns = {"NUMERO DE PRODUCTO", "DESCRIPCION", "PRECIO UNITARIO",
			"CANTIDAD", "PRECIO TOTAL"};
	private final InvoiceModel invoiceModel;
	private List<Item> items;
	
	public ItemTableModel(InvoiceModel invoiceModel) {
		this.invoiceModel = invoiceModel;
		items = this.invoiceModel.getItems();
	}
	
	@Override
	public int getColumnCount() {
		return columns.length;
	}

	@Override
	public int getRowCount() {
		return items.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Object object = null;
		switch (columnIndex) {
		case 0:
			object = items.get(rowIndex).getProduct().getId();
			break;
		case 1:
			object = items.get(rowIndex).getProduct().getDescription();
			break;
		case 2:
			object = items.get(rowIndex).getUnitPrice();
			break;
		case 3:
			object = items.get(rowIndex).getCant();
			break;
		case 4:
			object = items.get(rowIndex).getTotalPrice();
			break;
		default:
			break;
		}
		return object;
	}
	
	@Override
	public String getColumnName(int column) {
		return columns[column];
	}

}
